package com.jiangyg.mall.core.utils.springframework;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

/**
 * 工具描述：Spring应用全文工具类
 * 
 * @author jiangyg
 *
 */
@SuppressWarnings("unchecked")
public class ApplicationContextUtils implements ApplicationContextAware {

    private static ApplicationContext context;

    public void setApplicationContext(ApplicationContext context) throws BeansException {
        ApplicationContextUtils.context = context;
    }

    public static ApplicationContext getContext() {
        return context;
    }

    public static <T> T getBean(Class<T> requiredType) {
        return context.getBean(requiredType);
    }

    public static <T> T getBean(String name) {
        return (T) context.getBean(name);
    }

}
